package app.purchase.a571xz.com.myandroidframe.httpservice.request;


import java.io.UnsupportedEncodingException;
import java.util.TreeMap;

import app.purchase.a571xz.com.myandroidframe.config.AppConfig;
import app.purchase.a571xz.com.myandroidframe.httpservice.base.RequestBean;
import app.purchase.a571xz.com.myandroidframe.utils.MD5util;

public class LoginRequest extends RequestBean {
    //用户名	必须
    private String userName;
    //密码	必须
    private String password;
    //1普通账号密码登陆，2手机验证码登陆	必须
    private Integer type;

    private String signOpenApi;
    private String timeOpenApi;

    public LoginRequest(String userName, String password, Integer type){
        this.userName = strTo16(userName);
        this.password = strTo16(password);
        this.type = type;
        String currentTime = String.valueOf(System.currentTimeMillis());
        setTimeOpenApi(currentTime);
        TreeMap<String, String> signatureSortMap = new TreeMap<>();
        signatureSortMap.put("request_json_str_", currentTime);
        if (userName != null) {
            signatureSortMap.put("_userName", this.userName);
        } else {
            signatureSortMap.put("_userName", "");
        }
        signatureSortMap.put("_password", this.password);
        signatureSortMap.put("_type", String.valueOf(type));
        signatureSortMap.put("_signOpenApi", "");
        signatureSortMap.put("_timeOpenApi", currentTime);
        setSignOpenApi(MD5util.md5Password(setSignMap(signatureSortMap) + AppConfig.SIGN_KEY));
    }

    public String getSignOpenApi() {
        return signOpenApi;
    }

    public void setSignOpenApi(String signOpenApi) {
        this.signOpenApi = signOpenApi;
        System.out.println("当前验签" + signOpenApi);
    }

    public String getTimeOpenApi() {
        return timeOpenApi;
    }

    public void setTimeOpenApi(String timeOpenApi) {
        System.out.println("当前时间" + timeOpenApi);
        this.timeOpenApi = timeOpenApi;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

}